main()
{
	// Switch attackers
	if(!isDefined(level.switch_attackers))
		level.switch_attackers 	= [[level.setdvar]]("bp_switch_attackers", 0, 0, 4);

	if(!isDefined(level.firstRound))
		level.firstRound = true;

	if(level.switch_attackers == 4) // DaN 6-Round Switch
	{
		sixRoundSwitch();
	}
	else if(level.switch_attackers == 3) // King of the Hill
	{
		if(game["roundwinner"] == "allies")
		{
			game["attackers"] = "axis";
			game["defenders"] = "allies";
			
			game["axis_attack_count"]++;
		}
		else if(game["roundwinner"] == "axis")
		{
			game["attackers"] = "allies";
			game["defenders"] = "axis";
			
			game["allied_attack_count"]++;
		}
		else
		{
			randomAttacker();
		}
	}	
	else if(level.switch_attackers == 2) // Random Attacker
	{
		randomAttacker();
	}
	else if(level.switch_attackers == 1) // Switch Attackers
	{
		game["attackers"] = "axis";
		game["defenders"] = "allies";
	}
	else // Default
	{
		game["attackers"] = "allies";
		game["defenders"] = "axis";
	}
}

sixRoundSwitch()
{
	if(level.firstRound == true)
	{
		level.firstRound = false;
		rand = randomInt(100);
		
		if(rand < 50)
		{
			game["attackers"] = "axis";
			game["defenders"] = "allies";
			
			game["axis_attack_count"]++;
		}
		else
		{
			game["attackers"] = "allies";
			game["defenders"] = "axis";
			
			game["allied_attack_count"]++;
		}
	}
	else if(game["axis_attack_count"] > game["allied_attack_count"] && game["axis_attack_count"] < 6)
	{
		game["attackers"] = "axis";
		game["defenders"] = "allies";
		
		game["axis_attack_count"]++;
	}
	else if(game["axis_attack_count"] < game["allied_attack_count"] && game["allied_attack_count"] < 6)
	{
		game["attackers"] = "allies";
		game["defenders"] = "axis";
		
		game["allied_attack_count"]++;
	}
	else if(game["axis_attack_count"] > game["allied_attack_count"] && game["axis_attack_count"] == 6)
	{
		game["attackers"] = "allies";
		game["defenders"] = "axis";
		
		game["axis_attack_count"] = 0;
	}
	else if(game["axis_attack_count"] < game["allied_attack_count"] && game["allied_attack_count"] == 6)
	{
		game["attackers"] = "axis";
		game["defenders"] = "allies";
		
		game["allied_attack_count"] = 0;
	}
}

randomAttacker()
{
	buff = randomInt(3);
	rand = randomInt(100);
		
	if(game["allied_attack_count"] > (game["axis_attack_count"] + buff))
	{
		game["attackers"] = "axis";
		game["defenders"] = "allies";

		game["axis_attack_count"]++;
	} 
	else if(game["axis_attack_count"] > (game["allied_attack_count"] + buff))
	{
		game["attackers"] = "allies";
		game["defenders"] = "axis";
		
		game["allied_attack_count"]++;
	}
	else
	{
		if(rand < 50)
		{
			game["attackers"] = "axis";
			game["defenders"] = "allies";
			
			game["axis_attack_count"]++;
		}
		else
		{
			game["attackers"] = "allies";
			game["defenders"] = "axis";
			
			game["allied_attack_count"]++;
		}
	}
}